﻿' ***********************************************************************
' Assembly         : Ioc
' Author           : Tim Ford
' Created          : 10-02-2013
'
' Last Modified By : Tim Ford
' Last Modified On : 10-02-2013
' ***********************************************************************
' <copyright file="Container.vb" company="Red Baron Solutions">
'     Red Baron Solutions. All rights reserved.
' </copyright>
' <summary></summary>
' ***********************************************************************

Namespace Ioc
    ''' <summary>
    ''' 	
    ''' </summary>
    Public Class Container

        ''' <summary>
        ''' Initializes the <see cref="Container" /> class.	
        ''' </summary>
        ''' <remarks></remarks>
        Shared Sub New()
            m_Items = New System.Collections.Concurrent.ConcurrentDictionary(Of Type, WrappedIoc)
            m_SingletonType = GetType(SingleTypeInstance(Of ))
            Configuration.IocConfigurationContainer.AppSettings.ForEach(Sub(item)
                                                                            If Not item.IsMultipleInstances Then
                                                                                If item.IsCached Then
                                                                                    If item.IsDefault Then
                                                                                        SetSingletonIfNotSetCache(item.Type, item.InstanceType, item.IsLocked, item.CacheHours, item.CacheMinutes, item.CacheSeconds)
                                                                                    Else
                                                                                        SetSingletonCached(item.Type, item.InstanceType, item.IsLocked, item.CacheHours, item.CacheMinutes, item.CacheSeconds)
                                                                                    End If
                                                                                Else
                                                                                    If item.IsDefault Then
                                                                                        SetSingletonIfNotSet(item.Type, item.InstanceType, item.IsLocked)
                                                                                    Else
                                                                                        SetSingleton(item.Type, item.InstanceType, item.IsLocked)
                                                                                    End If
                                                                                End If
                                                                            Else
                                                                                If item.IsDefault Then
                                                                                    SetMultipleInstancesIfNotSet(item.Type, item.InstanceType, item.IsLocked)
                                                                                Else
                                                                                    SetMultipleInstances(item.Type, item.InstanceType, item.IsLocked)
                                                                                End If

                                                                            End If
                                                                        End Sub)
        End Sub

        Private Shared Function Items() As System.Collections.Concurrent.ConcurrentDictionary(Of Type, WrappedIoc)
            Return m_Items
        End Function

        Private Shared ReadOnly m_Items As System.Collections.Concurrent.ConcurrentDictionary(Of Type, WrappedIoc)
        Private Shared ReadOnly m_SingletonType As Type


  
#Region " Singleton "

        Private Shared Sub SetSingleton(type As String, instanceType As String, isLocked As Boolean)
            If Not String.IsNullOrWhiteSpace(type) And Not String.IsNullOrWhiteSpace(instanceType) Then
                SetSingleton(ObjectFactory.ResolveType(type), ObjectFactory.ResolveType(instanceType), isLocked)
            Else
                If Not String.IsNullOrWhiteSpace(type) Then
                    Throw New ArgumentException("Instance type is required")
                Else
                    Throw New ArgumentException("Type is required")
                End If
            End If
        End Sub

        ''' <summary>
        ''' Sets the singleton.	
        ''' </summary>
        ''' <typeparam name="T"></typeparam>
        ''' <param name="instance">The instance.</param>
        ''' <remarks></remarks>
        Public Shared Sub SetSingleton(Of T)(instance As T)
            SetSingleton(Of T)(instance, False)
        End Sub

        ''' <summary>
        ''' Sets the singleton.	
        ''' </summary>
        ''' <typeparam name="T"></typeparam>
        ''' <param name="instance">The instance.</param>
        ''' <param name="isLocked">The is locked.</param>
        ''' <remarks></remarks>
        Public Shared Sub SetSingleton(Of T)(instance As T, isLocked As Boolean)
            If instance Is Nothing Then
                Return
            End If
            Dim type As Type = GetType(T)
            SetIocObject(type, New SingleInstance(instance), isLocked)
        End Sub

        ''' <summary>
        ''' Sets the singleton.	
        ''' </summary>
        ''' <param name="type">The type.</param>
        ''' <param name="instanceType">Type of the instance.</param>
        ''' <remarks></remarks>
        Public Shared Sub SetSingleton(type As Type, instanceType As Type)
            SetSingleton(type, instanceType, False)
        End Sub


        ''' <summary>
        ''' Sets the singleton.	
        ''' </summary>
        ''' <param name="type">The type.</param>
        ''' <param name="instanceType">Type of the instance.</param>
        ''' <param name="isLocked">The is locked.</param>
        ''' <remarks></remarks>
        Public Shared Sub SetSingleton(type As Type, instanceType As Type, isLocked As Boolean)
            If type IsNot Nothing AndAlso instanceType IsNot Nothing Then
                Dim instance As Object = ObjectFactory.CreateGenericItem(GetType(SingleInstance(Of )), instanceType)
                SetIocObject(type, DirectCast(instance, IIIocObject), isLocked)
            End If
        End Sub


#End Region
#Region " Singleton Cache "

 



        Private Shared Sub SetSingletonCached(type As String, instanceType As String, isLocked As Boolean, hours As Integer, minutes As Integer, seconds As Integer)
            If Not String.IsNullOrWhiteSpace(type) And Not String.IsNullOrWhiteSpace(instanceType) Then
                If hours > 0 Or minutes > 0 Or seconds > 0 Then
                    Dim timeSpan As New TimeSpan(If(hours < 0, 0, hours), If(minutes < 0, 0, minutes), If(seconds < 0, 0, seconds))
                    SetSingletonCached(ObjectFactory.ResolveType(type), ObjectFactory.ResolveType(instanceType), timeSpan, isLocked)
                Else
                    SetSingletonCached(ObjectFactory.ResolveType(type), ObjectFactory.ResolveType(instanceType), isLocked)
                End If

            Else
                If Not String.IsNullOrWhiteSpace(type) Then
                    Throw New ArgumentException("Instance type is required")
                Else
                    Throw New ArgumentException("Type is required")
                End If
            End If
        End Sub

        ''' <summary>
        ''' Sets the singleton cached.	
        ''' </summary>
        ''' <typeparam name="T"></typeparam>
        ''' <param name="instance">The instance.</param>
        ''' <remarks></remarks>
        Public Shared Sub SetSingletonCached(Of T)(instance As T)
            SetSingletonCached(Of T)(instance, False)
        End Sub

        ''' <summary>
        ''' Sets the singleton cached.	
        ''' </summary>
        ''' <typeparam name="T"></typeparam>
        ''' <param name="instance">The instance.</param>
        ''' <param name="isLocked">The is locked.</param>
        ''' <remarks></remarks>
        Public Shared Sub SetSingletonCached(Of T)(instance As T, isLocked As Boolean)
            If instance Is Nothing Then
                Return
            End If
            Dim type As Type = GetType(T)
            SetIocObject(type, New SingleInstanceCached(type, instance), isLocked)
        End Sub

        ''' <summary>
        ''' Sets the singleton cached.	
        ''' </summary>
        ''' <param name="type">The type.</param>
        ''' <param name="instanceType">Type of the instance.</param>
        ''' <remarks></remarks>
        Public Shared Sub SetSingletonCached(type As Type, instanceType As Type)
            SetSingletonCached(type, instanceType, Nothing, False)
        End Sub

        ''' <summary>
        ''' Sets the singleton cached.	
        ''' </summary>
        ''' <param name="type">The type.</param>
        ''' <param name="instanceType">Type of the instance.</param>
        ''' <param name="isLocked">The is locked.</param>
        ''' <remarks></remarks>
        Public Shared Sub SetSingletonCached(type As Type, instanceType As Type, isLocked As Boolean)
            SetSingletonCached(type, instanceType, Nothing, isLocked)
        End Sub

        ''' <summary>
        ''' Sets the singleton cached.	
        ''' </summary>
        ''' <param name="type">The type.</param>
        ''' <param name="instanceType">Type of the instance.</param>
        ''' <param name="timeSpan">The time span.</param>
        ''' <remarks></remarks>
        Public Shared Sub SetSingletonCached(type As Type, instanceType As Type, timeSpan As TimeSpan)
            SetSingletonCached(type, instanceType, timeSpan, False)
        End Sub
        ''' <summary>
        ''' Sets the singleton cached.	
        ''' </summary>
        ''' <param name="type">The type.</param>
        ''' <param name="instanceType">Type of the instance.</param>
        ''' <param name="timeSpan">The time span.</param>
        ''' <param name="isLocked">The is locked.</param>
        ''' <remarks></remarks>
        Public Shared Sub SetSingletonCached(type As Type, instanceType As Type, timeSpan As TimeSpan, isLocked As Boolean)
            If type IsNot Nothing AndAlso instanceType IsNot Nothing Then
                SetIocObject(type, New SingleInstanceCached(type, instanceType) With {.DefaultTimeSpan = timeSpan}, isLocked)
            End If
        End Sub


#End Region

#Region " Single to Set if not Set "
     

        Private Shared Sub SetSingletonIfNotSet(type As String, instanceType As String, isLocked As Boolean)
            If Not String.IsNullOrWhiteSpace(type) And Not String.IsNullOrWhiteSpace(instanceType) Then
                SetSingletonIfNotSet(ObjectFactory.ResolveType(type), ObjectFactory.ResolveType(instanceType), isLocked)
            Else
                If Not String.IsNullOrWhiteSpace(type) Then
                    Throw New ArgumentException("Instance type is required")
                Else
                    Throw New ArgumentException("Type is required")
                End If
            End If
        End Sub
        ''' <summary>
        ''' Sets the singleton if not set.	
        ''' </summary>
        ''' <typeparam name="T"></typeparam>
        ''' <param name="instance">The instance.</param>
        ''' <remarks></remarks>
        Public Shared Sub SetSingletonIfNotSet(Of T)(instance As T)
            SetSingletonIfNotSet(Of T)(instance, False)
        End Sub

        ''' <summary>
        ''' Sets the singleton if not set.	
        ''' </summary>
        ''' <typeparam name="T"></typeparam>
        ''' <param name="instance">The instance.</param>
        ''' <param name="isLocked">The is locked.</param>
        ''' <remarks></remarks>
        Public Shared Sub SetSingletonIfNotSet(Of T)(instance As T, isLocked As Boolean)
            If instance Is Nothing Then
                Return
            End If
            Dim type As Type = GetType(T)
            If Items.ContainsKey(type) Then
                Return
            End If
            SetIocObject(type, New SingleInstance(instance), isLocked)
        End Sub

        ''' <summary>
        ''' Sets the singleton if not set.	
        ''' </summary>
        ''' <param name="type">The type.</param>
        ''' <param name="instanceType">Type of the instance.</param>
        ''' <remarks></remarks>
        Public Shared Sub SetSingletonIfNotSet(type As Type, instanceType As Type)
            SetSingletonIfNotSet(type, instanceType, False)
        End Sub


        ''' <summary>
        ''' Sets the singleton if not set.	
        ''' </summary>
        ''' <param name="type">The type.</param>
        ''' <param name="instanceType">Type of the instance.</param>
        ''' <param name="isLocked">The is locked.</param>
        ''' <remarks></remarks>
        Public Shared Sub SetSingletonIfNotSet(type As Type, instanceType As Type, isLocked As Boolean)
            If instanceType Is Nothing Then
                Return
            End If
            If Items.ContainsKey(type) Then
                Return
            End If
            SetSingleton(type, instanceType, isLocked)
        End Sub

 

#End Region

#Region " Singleton Set if not set Cache "
        Private Shared Sub SetSingletonIfNotSetCache(type As String, instanceType As String, isLocked As Boolean, hours As Integer, minutes As Integer, seconds As Integer)
            If Not String.IsNullOrWhiteSpace(type) And Not String.IsNullOrWhiteSpace(instanceType) Then
                If hours > 0 Or minutes > 0 Or seconds > 0 Then
                    Dim timeSpan As New TimeSpan(If(hours < 0, 0, hours), If(minutes < 0, 0, minutes), If(seconds < 0, 0, seconds))
                    SetSingletonIfNotSetCache(ObjectFactory.ResolveType(type), ObjectFactory.ResolveType(instanceType), timeSpan, isLocked)
                Else
                    SetSingletonIfNotSetCache(ObjectFactory.ResolveType(type), ObjectFactory.ResolveType(instanceType), isLocked)
                End If

            Else
                If Not String.IsNullOrWhiteSpace(type) Then
                    Throw New ArgumentException("Instance type is required")
                Else
                    Throw New ArgumentException("Type is required")
                End If
            End If
        End Sub
        ''' <summary>
        ''' Sets the singleton if not set cache.	
        ''' </summary>
        ''' <typeparam name="T"></typeparam>
        ''' <param name="instance">The instance.</param>
        ''' <remarks></remarks>
        Public Shared Sub SetSingletonIfNotSetCache(Of T)(instance As T)
            If instance Is Nothing Then
                Return
            End If
            Dim type As Type = GetType(T)
            If Items.ContainsKey(type) Then
                Return
            End If
            SetSingleton(Of T)(instance)
        End Sub

        ''' <summary>
        ''' Sets the singleton cached.	
        ''' </summary>
        ''' <param name="type">The type.</param>
        ''' <param name="instanceType">Type of the instance.</param>
        ''' <remarks></remarks>
        Public Shared Sub SetSingletonIfNotSetCache(type As Type, instanceType As Type)
            SetSingletonIfNotSetCache(type, instanceType, Nothing, False)
        End Sub

        ''' <summary>
        ''' Sets the singleton cached.	
        ''' </summary>
        ''' <param name="type">The type.</param>
        ''' <param name="instanceType">Type of the instance.</param>
        ''' <param name="isLocked">The is locked.</param>
        ''' <remarks></remarks>
        Public Shared Sub SetSingletonIfNotSetCache(type As Type, instanceType As Type, isLocked As Boolean)
            SetSingletonIfNotSetCache(type, instanceType, Nothing, isLocked)
        End Sub

        ''' <summary>
        ''' Sets the singleton cached.	
        ''' </summary>
        ''' <param name="type">The type.</param>
        ''' <param name="instanceType">Type of the instance.</param>
        ''' <param name="timeSpan">The time span.</param>
        ''' <remarks></remarks>
        Public Shared Sub SetSingletonIfNotSetCache(type As Type, instanceType As Type, timeSpan As TimeSpan)
            SetSingletonIfNotSetCache(type, instanceType, timeSpan, False)
        End Sub
        ''' <summary>
        ''' Sets the singleton cached.	
        ''' </summary>
        ''' <param name="type">The type.</param>
        ''' <param name="instanceType">Type of the instance.</param>
        ''' <param name="timeSpan">The time span.</param>
        ''' <param name="isLocked">The is locked.</param>
        ''' <remarks></remarks>
        Public Shared Sub SetSingletonIfNotSetCache(type As Type, instanceType As Type, timeSpan As TimeSpan, isLocked As Boolean)
            If Items.ContainsKey(type) Then
                Return
            End If
            SetSingletonCached(type, instanceType, timeSpan, isLocked)
        End Sub

#End Region

#Region " Mulitiple Instances "



        Private Shared Sub SetMultipleInstances(type As String, instanceType As String, isLocked As Boolean)
            If Not String.IsNullOrWhiteSpace(type) And Not String.IsNullOrWhiteSpace(instanceType) Then
                SetMultipleInstances(ObjectFactory.ResolveType(type), ObjectFactory.ResolveType(instanceType), isLocked)
            Else
                If Not String.IsNullOrWhiteSpace(type) Then
                    Throw New ArgumentException("Instance type is required")
                Else
                    Throw New ArgumentException("Type is required")
                End If
            End If

        End Sub

        ''' <summary>
        ''' Sets the multiple instances.	
        ''' </summary>
        ''' <param name="type">The type.</param>
        ''' <param name="instanceType">Type of the instance.</param>
        ''' <remarks></remarks>
        Public Shared Sub SetMultipleInstances(type As Type, instanceType As Type)
            If type IsNot Nothing AndAlso instanceType IsNot Nothing Then
                SetIocObject(type, New MultipleInstance(instanceType))
            End If
        End Sub

        ''' <summary>
        ''' Sets the multiple instances.	
        ''' </summary>
        ''' <param name="type">The type.</param>
        ''' <param name="instanceType">Type of the instance.</param>
        ''' <param name="isLocked">The is locked.</param>
        ''' <remarks></remarks>
        Public Shared Sub SetMultipleInstances(type As Type, instanceType As Type, isLocked As Boolean)
            If type IsNot Nothing AndAlso instanceType IsNot Nothing Then
                SetIocObject(type, New MultipleInstance(instanceType), isLocked)
            End If
        End Sub

        ''' <summary>
        ''' Sets the multiple instances.	
        ''' </summary>
        ''' <typeparam name="T"></typeparam>
        ''' <param name="instanceType">Type of the instance.</param>
        ''' <remarks></remarks>
        Public Shared Sub SetMultipleInstances(Of T)(instanceType As Type)
            If instanceType Is Nothing Then
                Return
            End If
            Dim type As Type = GetType(T)
            SetIocObject(type, New MultipleInstance(instanceType))
        End Sub

        ''' <summary>
        ''' Sets the multiple instances.	
        ''' </summary>
        ''' <typeparam name="T"></typeparam>
        ''' <param name="instanceType">Type of the instance.</param>
        ''' <param name="isLocked">The is locked.</param>
        ''' <remarks></remarks>
        Public Shared Sub SetMultipleInstances(Of T)(instanceType As Type, isLocked As Boolean)
            If instanceType Is Nothing Then
                Return
            End If
            Dim type As Type = GetType(T)
            SetIocObject(type, New MultipleInstance(instanceType), isLocked)
        End Sub

        ''' <summary>
        ''' Sets the multiple instances.	
        ''' </summary>
        ''' <typeparam name="T"></typeparam>
        ''' <param name="instance">The instance.</param>
        ''' <remarks></remarks>
        Public Shared Sub SetMultipleInstances(Of T)(instance As Func(Of Object))
            If instance Is Nothing Then
                Return
            End If
            Dim type As Type = GetType(T)
            SetIocObject(type, New MultipleInstance(instance))
        End Sub

        ''' <summary>
        ''' Sets the multiple instances.	
        ''' </summary>
        ''' <typeparam name="T"></typeparam>
        ''' <param name="instance">The instance.</param>
        ''' <param name="isLocked">The is locked.</param>
        ''' <remarks></remarks>
        Public Shared Sub SetMultipleInstances(Of T)(instance As Func(Of Object), isLocked As Boolean)
            If instance Is Nothing Then
                Return
            End If
            Dim type As Type = GetType(T)
            SetIocObject(type, New MultipleInstance(instance), isLocked)
        End Sub
#End Region

#Region " Mutlitple if not set "
        Private Shared Sub SetMultipleInstancesIfNotSet(type As String, instanceType As String, isLocked As Boolean)
            If Not String.IsNullOrWhiteSpace(type) And Not String.IsNullOrWhiteSpace(instanceType) Then
                SetMultipleInstancesIfNotSet(ObjectFactory.ResolveType(type), ObjectFactory.ResolveType(instanceType), isLocked)
            Else
                If Not String.IsNullOrWhiteSpace(type) Then
                    Throw New ArgumentException("Instance type is required")
                Else
                    Throw New ArgumentException("Type is required")
                End If
            End If
        End Sub

        ''' <summary>
        ''' Sets the multiple instances.	
        ''' </summary>
        ''' <param name="type">The type.</param>
        ''' <param name="instanceType">Type of the instance.</param>
        ''' <remarks></remarks>
        Public Shared Sub SetMultipleInstancesIfNotSet(type As Type, instanceType As Type)
            If Items.ContainsKey(type) Then
                Return
            End If
            If type IsNot Nothing AndAlso instanceType IsNot Nothing Then
                SetIocObject(type, New MultipleInstance(instanceType))
            End If
        End Sub

        ''' <summary>
        ''' Sets the multiple instances.	
        ''' </summary>
        ''' <param name="type">The type.</param>
        ''' <param name="instanceType">Type of the instance.</param>
        ''' <param name="isLocked">The is locked.</param>
        ''' <remarks></remarks>
        Public Shared Sub SetMultipleInstancesIfNotSet(type As Type, instanceType As Type, isLocked As Boolean)
            If Items.ContainsKey(type) Then
                Return
            End If
            If type IsNot Nothing AndAlso instanceType IsNot Nothing Then
                SetIocObject(type, New MultipleInstance(instanceType), isLocked)
            End If
        End Sub

        ''' <summary>
        ''' Sets the multiple instances.	
        ''' </summary>
        ''' <typeparam name="T"></typeparam>
        ''' <param name="instanceType">Type of the instance.</param>
        ''' <remarks></remarks>
        Public Shared Sub SetMultipleInstancesIfNotSet(Of T)(instanceType As Type)
            If instanceType Is Nothing Then
                Return
            End If
            Dim type As Type = GetType(T)
            If Items.ContainsKey(type) Then
                Return
            End If
            SetIocObject(type, New MultipleInstance(instanceType))
        End Sub

        ''' <summary>
        ''' Sets the multiple instances.	
        ''' </summary>
        ''' <typeparam name="T"></typeparam>
        ''' <param name="instanceType">Type of the instance.</param>
        ''' <param name="isLocked">The is locked.</param>
        ''' <remarks></remarks>
        Public Shared Sub SetMultipleInstancesIfNotSet(Of T)(instanceType As Type, isLocked As Boolean)
            If instanceType Is Nothing Then
                Return
            End If
            Dim type As Type = GetType(T)
            If Items.ContainsKey(type) Then
                Return
            End If
            SetIocObject(type, New MultipleInstance(instanceType), isLocked)
        End Sub

        ''' <summary>
        ''' Sets the multiple instances.	
        ''' </summary>
        ''' <typeparam name="T"></typeparam>
        ''' <param name="instance">The instance.</param>
        ''' <remarks></remarks>
        Public Shared Sub SetMultipleInstancesIfNotSet(Of T)(instance As Func(Of Object))
            If instance Is Nothing Then
                Return
            End If
            Dim type As Type = GetType(T)
            If Items.ContainsKey(type) Then
                Return
            End If
            SetIocObject(type, New MultipleInstance(instance))
        End Sub

        ''' <summary>
        ''' Sets the multiple instances.	
        ''' </summary>
        ''' <typeparam name="T"></typeparam>
        ''' <param name="instance">The instance.</param>
        ''' <param name="isLocked">The is locked.</param>
        ''' <remarks></remarks>
        Public Shared Sub SetMultipleInstancesIfNotSet(Of T)(instance As Func(Of Object), isLocked As Boolean)
            If instance Is Nothing Then
                Return
            End If
            Dim type As Type = GetType(T)
            If Items.ContainsKey(type) Then
                Return
            End If
            SetIocObject(type, New MultipleInstance(instance), isLocked)
        End Sub
#End Region
#Region " Set the Ioc Object "
        ''' <summary>
        ''' Sets the ioc object.	
        ''' </summary>
        ''' <param name="type">The type.</param>
        ''' <param name="iIIocObject">The i I ioc object.</param>
        ''' <remarks></remarks>
        Public Shared Sub SetIocObject(type As Type, iIIocObject As IIIocObject)
            SetIocObject(type, iIIocObject, False)
        End Sub

        ''' <summary>
        ''' Sets the ioc object.	
        ''' </summary>
        ''' <param name="type">The type.</param>
        ''' <param name="iIIocObject">The i I ioc object.</param>
        ''' <param name="isLocked">The is locked.</param>
        ''' <remarks></remarks>
        Public Shared Sub SetIocObject(type As Type, iIIocObject As IIIocObject, isLocked As Boolean)
            If type Is Nothing OrElse iIIocObject Is Nothing Then
                Return
            End If

            If Items.ContainsKey(type) Then
                Dim item As WrappedIoc = Items(type)
                If item.IsLocked Then
                    Return
                End If
                Items(type) = New WrappedIoc(isLocked, iIIocObject)
            Else
                Items.TryAdd(type, New WrappedIoc(isLocked, iIIocObject))
            End If

        End Sub

#End Region

#Region " Get the Ioc Object "

        ''' <summary>
        ''' Instances the is set.	
        ''' </summary>
        ''' <typeparam name="T"></typeparam>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Shared Function InstanceIsSet(Of T)() As Boolean
            Dim type As Type = GetType(T)
            Return Items.ContainsKey(type)
        End Function

        ''' <summary>
        ''' Gets the instance.	
        ''' </summary>
        ''' <typeparam name="T"></typeparam>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Shared Function GetInstance(Of T)() As T
            Dim type As Type = GetType(T)
            Return If(Items.ContainsKey(type), DirectCast(Items(type).IIIocObject.GetObject, T), Nothing)
        End Function

        ''' <summary>
        ''' Gets the instance object.	
        ''' </summary>
        ''' <param name="type">The type.</param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Shared Function GetInstanceObject(type As Type) As Object
            If Items.ContainsKey(type) Then
                Return Items(type).IIIocObject.GetObject
            Else
                Return Nothing
            End If

        End Function

#End Region

#Region " Finalize and Displose "
        ''' <summary>
        ''' Finalizes this instance.	
        ''' </summary>
        ''' <remarks></remarks>
        Protected Overrides Sub Finalize()
            For Each item As KeyValuePair(Of Type, WrappedIoc) In Items()
                Dim dispose As IDisposable = TryCast(item.Value, IDisposable)
                If dispose IsNot Nothing Then
                    dispose.Dispose()
                End If
            Next
            MyBase.Finalize()
        End Sub
#End Region

    End Class

End Namespace
